<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>


<script type="text/javascript">
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to Delete?");
if (agree)
	return true ;
else
	return false ;
}


function checkEmpty(label,value)
{

	v = document.getElementById(label).value ;
	v1=document.getElementById(value).value;
	if ((v == "")||(v1=="")) {
    	alert("Enter the label and value both.");
    	 return false;        
    }
	
}
	function dis()
	{
		if(document.getElementById('newAttributeValue').style.display=='block')
		{
			document.getElementById('newAttributeValue').style.display='none';
		}
		else
		{
			document.getElementById('newAttributeValue').style.display='block';
		}
	}
</script>

<div><b>Attribute Set</b> ${attributeSet.name} (Id=${attributeSet.uuid})</div>

<div><b>Edit Attribute</b> ${attribute.name} (Id=${attribute.uuid})</div>

	<table>
		<tr><td><b>Name</b></td><td>${attribute.name}</td></tr>
	</table>
<br/>
<s:if test="attribute.multivalued == true">		
<div><a href="#" onclick="dis()"><b>Add new Value</b></a></div>
</s:if>
<div id="newAttributeValue" style="display:none">
<form name="addAttributeValue" action="addAttributeValue" method="post" onsubmit="return checkEmpty('label','value')">
	<table>
		<tr>
			<td><b>Attribute Type</b></td>
			<td><select name="attributeType">
				<option value="checkbox">Check Box</option>
				<option value="dropdown">Drop Down</option>
				<option value="radio">radio</option>
				</select></td>
		</tr>
		<tr>
			<td><b>Label</b></td>
			<td>
				<input type="text" name="valuelabel" value="" id="label">
				<input type="hidden" name="uuid" value="${attributeSet.uuid}">
				<input type="hidden" name="attributeUuid" value="${attribute.uuid}">
				<input type="hidden" name="p" value="${p}">
				<input type="hidden" name="backUrl" value="${backUrl}">
			</td>
		</tr>
		<tr>
			<td>
				<b>Value</b>
			</td>
			<td>
				<input type="text" name="StringValue" value="" id="value">
			</td>
		</tr>
		<tr>
			<td></td><td><input type="submit" name="Create" value="Create"> <a href="#" onclick="dis()"><input type="button" name="Cancel" value="Cancel"></a></td>
		</tr>
	</table>
</form>
</div>
<br/>
<s:if test="attribute.multivalued == true">			
				<div><b>Attribute Values</b></div>

	
	<table>
		<tr><td><b>Id</b></td><td><b>Type</b></td><td><b>Label</b></td><td><b>Value</b></td></tr>
		<s:if test="attributeValues.size() > 0">
				<s:iterator value="attributeValues" var="av">
					<s:if test="%{(#av.attributeType=='dropdown')||(#av.attributeType=='radio')}">
						<s:property value="setOptionsValues(#av.stringValue)"/>
						<tr><td>${av.uuid}</td><td>${av.attributeType}</td><td>${av.label}</td><td></td>
							<td>
								<form method="post" name="editValue" action="editValue">
									<input type="hidden" name="p" value="${p}">
									<input type="hidden" name="uuid" value="${attributeSet.uuid}">
									<input type="hidden" name="attributeUuid" value="${attribute.uuid}">
									<input type="hidden" name="valueUuid" value="${av.uuid}">		
									<input type="submit" name="submit" value="Manage">
								</form>
							</td>
							<td>
								<form method="post" name="deleteAttributeValue_${av.uuid}" action="deleteAttributeValue" onsubmit="return confirmSubmit()">
									<input type="hidden" name="p" value="${p}">
									<input type="hidden" name="attributeUuid" value="${attribute.uuid}">
									<input type="hidden" name="uuid" value="${attributeSet.uuid}">
									<input type="hidden" name="valueUuid" value="${av.uuid}">	
									<input type="hidden" name="backUrl" value="${backUrl}">	
									<input type="submit" name="submit" value="Delete">
								</form>
							</td>
							</tr>
					</s:if>
					<s:else>
							<form method="post" name="changeSingleValue_${av.uuid}" action="changeSingleValue" onsubmit="return checkEmpty('${av.uuid}_l','${av.uuid}_v')">
							<tr><td>${av.uuid}</td><td>${av.attributeType}</td>
							<td><input type="text" name="valuelabel" value="${av.label}" id="${av.uuid}_l"></td>
							<td><input type="text" name="stringValue" value="${av.stringValue}" id="${av.uuid}_v">
							<input type="hidden" name="valueUuid" value="${av.uuid}">
							<input type="hidden" name="uuid" value="${attributeSet.uuid}">
							<input type="hidden" name="p" value="${p}">
							<input type="hidden" name="attributeUuid" value="${attribute.uuid}">
							<input type="hidden" name="backUrl" value="${backUrl}">
							</td>
							<td><input type="submit" name="submit" value="Change"></td>
							
							</form>
							<td>
								<form method="post" name="deleteAttributeValue_${av.uuid}s" action="deleteAttributeValue" onsubmit="return confirmSubmit()">
									<input type="hidden" name="p" value="${p}">
									<input type="hidden" name="attributeUuid" value="${attribute.uuid}">
									<input type="hidden" name="valueUuid" value="${av.uuid}">	
									<input type="hidden" name="backUrl" value="${backUrl}">	
									<input type="hidden" name="uuid" value="${attributeSet.uuid}">
									<input type="submit" name="submit" value="Delete">
								</form>
							</td>
							</tr>
					</s:else>
				</s:iterator>
			
		</s:if>	
	</table>
</s:if>

<div><a href="${backUrl}"><b>Back</b></a></div>